package com.yanqu.road.server.cmd.activity.chuhan.cross;

import com.yanqu.road.entity.autodata.chuhan.config.ChuHanBuffTypeConfig;
import com.yanqu.road.entity.enums.eChuHanBuffType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.logic.activity.chuhan.ChuHanConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChuHanProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.tongbing.ChuHanMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_CHUHAN_GET_DATA_FROM_CROSS, desc = "")
public class ChuHanGetDataFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ChuHanProto.ChuHanGetDataRespMsg syncMsg = ChuHanProto.ChuHanGetDataRespMsg.parseFrom(packet.getBytes());
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(packet.getPlayerId());
        if (onlinePlayer != null) {
            ChuHanConfig config = ChuHanMgr.getConfig();
            if (config == null) {
                return;
            }
            //如果有PVE BUFF 是给兵符的,给玩家加到背包里
            for (Integer buffId : syncMsg.getPveBuffIdList()) {
                ChuHanBuffTypeConfig buffTypeConfig = config.getBuffTypeConfigMap().get(buffId);
                if (buffTypeConfig == null) {
                    continue;
                }

                if (buffTypeConfig.getType() == eChuHanBuffType.Type12_BingFuReward.getValue()){
                    int itemId = config.getBingFuItem();
                    int itemNum = buffTypeConfig.getBuffParamsByLevel(1).get(0);
                    onlinePlayer.getModule(CurrencyModule.class).addCurrency(new Property(itemId, itemNum), eLogMoneyType.ChuHan, eLogMoneyType.ChuHanPveBuffAdd);
                }
            }

            onlinePlayer.sendPacket(Protocol.S_CHUHAN_GET_DATA % 20000, syncMsg.toBuilder());
        }
    }

}
